/*pr0tUH1dV1X/xaCwJNPKCI66uP1N0pw08ls9hPy4qUdK9x/PECvdKNzCjrZO1Fs5*/
import { PAGECODE, STATUS, FIELD, DataSource } from '../../constance';
import initButtonState from '../init/initButtonState';
import pageInfoClick from './queryPageInfo';

/**
 * 取消
 * @param {*} pageModel 
 */
export default function (pageModel) {
    const { spaCache, promptBox } = pageModel;
    const { getCacheById } = spaCache;
    // multiLangData['4004POORDER-000031'], 
    promptBox({
        /* 国际化处理： 确认要取消吗？*/
        color: "info",
        title: "取消",
        content: "确认要取消吗",
        beSureBtnClick: () => {
            //设置页面状态为浏览态
            pageModel.updatePageStatus(STATUS.browse);
            let pk_order = pageModel.pageTo.getUrlParam(FIELD.id);
            if (!pk_order || pk_order == 'undefined' || pk_order == 'null') {
                pk_order = pageModel.get(PAGECODE.cardHead).getItemsValue(FIELD.pk);
                pk_order = pk_order && pk_order.value;
            }
            if (pk_order) {
                const dataSource = DataSource;
                let cardData = getCacheById(pk_order, dataSource);
                // 先从缓存中获取，缓存中有，使用缓存中的，缓存中没有，发请求查询
                if (cardData) {
                    pageModel.get(PAGECODE.cardHead).setData({ formDataObj: { [PAGECODE.cardHead]: cardData.head[PAGECODE.cardHead] } });
                    pageModel.get(PAGECODE.cardbody1).setData(cardData.bodys[PAGECODE.cardbody1]);
                    pageModel.get(PAGECODE.cardbody2).setData(cardData.bodys[PAGECODE.cardbody2]);
                } else {
                    pageInfoClick(pageModel, pk_order);
                }
            } else {
                pageModel.get(PAGECODE.cardHead).clearData();
                pageModel.get(PAGECODE.cardbody1).setData({ rows: [] });
                pageModel.get(PAGECODE.cardbody2).setData({ rows: [] });
            }
            // 将页面状态置为浏览态
            pageModel.get(PAGECODE.cardHead).setStatus(STATUS.browse);
            initButtonState(pageModel);
        },
    });
}
/*pr0tUH1dV1X/xaCwJNPKCI66uP1N0pw08ls9hPy4qUdK9x/PECvdKNzCjrZO1Fs5*/